<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="row  border-bottom white-bg dashboard-header">
        <div class="col-sm-6">
            <h2>发送短息测试</h2>
            <div class="wrapper wrapper-content animated fadeInRight ibox-content">
		        <form class="form-horizontal m" id="form-smsTemplate-add">
					<div class="form-group">	
						<label class="col-sm-3 control-label">模版ID：</label>
						<div class="col-sm-8">
							<input id="templateId" name="templateId" class="form-control" type="text">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">手机号码：</label>
						<div class="col-sm-8">
							<input id="phone" name="phone" class="form-control" type="text">
						</div>
					</div>
					<div class="form-group">
						<div class="form-control-static col-sm-offset-9">
							<button type="submit" class="btn btn-primary">发送</button>
						</div>
					</div>
				</form>
			</div>
        </div>
        <div class="col-sm-6">
            <h2>验证短信验证码：</h2>
            <div class="wrapper wrapper-content animated fadeInRight ibox-content">
		        <form class="form-horizontal m" id="form-smsTemplate-add2">
		        	<input type="hidden" id="msgOrderNo" name="msgOrderNo"/>
		        	<div class="form-group">	
						<label class="col-sm-3 control-label">手机号码：</label>
						<div class="col-sm-8">
							<input id="vphone" name="vphone" class="form-control" type="text">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">短信验证码：</label>
						<div class="col-sm-8">
							<input id="verifyCode" name="verifyCode" class="form-control" type="text">
						</div>
					</div>
					<div class="form-group">
						<div class="form-control-static col-sm-offset-9">
							<button type="button" class="btn btn-primary" onclick="verifyCodeSend();">验证</button>
						</div>
					</div>
				</form>
			</div>
        </div>
    </div>
	
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "message/sysSmsTemplate"
		$("#form-smsTemplate-add").validate({
			rules:{
				xxxx:{
					required:true,
				}
        	},
			submitHandler: function(form) {
				send()
			}
		});
		
		
		function send() {
        	var templateId = $("input[name='templateId']").val();
        	var phone = $("input[name='phone']").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "message/sysSmsTemplate/send",
        		data : {
        			"templateId": templateId,
        			"phone": phone
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.modal.alertSuccess(data.msg);
        			 $("input[name='templateId']").val("");
        			 $("input[name='phone']").val("");
        			 $("input[name='msgOrderNo']").val(data.msgOrderNo);
        			 $("input[name='vphone']").val(phone);
        		}
        	});
        }
		
		function verifyCodeSend() {
        	var verifyCode = $("input[name='verifyCode']").val();
        	var msgOrderNo = $("input[name='msgOrderNo']").val();
        	var phone = $("input[name='vphone']").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "message/sysSmsTemplate/verifyCode",
        		data : {
        			"verifyCode": verifyCode,
        			"msgOrderNo": msgOrderNo,
        			"phone": phone
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.modal.alertSuccess(data.msg);
        			 $("input[name='verifyCode']").val("");
        			 $("input[name='msgOrderNo']").val("");
        			 $("input[name='vphone']").val("");
        			 
        		}
        	});
        }
	</script>
</body>
</html>
